import { find_date_format, start_day, end_day, for_obj, utc_8, loc } from 'sui';
import { utc_offset } from 'cache';

const cell_row = (row) => {
    const utc = utc_offset();

    row.forEach((d, i) => {
        d["time"] = utc_8(d["time"], utc);
        d["index"] = i + 1;
    });
};

const cell_col = (cell) => {
    let col = [
        {name: loc("xh"), key: 'index', width: 90},
        {name: loc("cmd_9"), key: 'time', width: 170},
    ];

    for_obj(cell, (k, v) => {
        if (k === "index" || k === "time" || k === "dtp" || k === "ti") {
            return;
        }

        col.push({name: k, key: k, width: 200});
    });

    return col;
};

const cell_para = (cell) => {
    let col = [];

    for_obj(cell, (k, v) => {
        if (k === "index" || k === "time" || k === "dtp" || k === "ti") {
            return;
        }

        col.push({id: k, des: k});
    });

    return col;
};

const get_init = (optFind) => {
    const s = start_day();
    const e = end_day();

    optFind({
        t_start: s,
        t_end: e,
        time: find_date_format(s, e, "datetime"),
    });
};

export {get_init, cell_para, cell_row, cell_col};
